package Server.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * Entity - 会员
 *
 * @author xvzhe
 * @version 0.1
 *
 */
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
public class Users {

    @Id
    @GeneratedValue(generator = "NumberIdProduce")
    @GenericGenerator(name="NumberIdProduce", strategy="Server.tool.NumberIdProduce")
    private String uuid;

    /*
    * 会员角色
    *
    * */

    @ManyToOne
    @JoinColumn(name = "roleId")
    private  Role role;

    /*
    *
    *登录名
    *
    * */

    @Column(unique=true)
    private String username;

    /*
    * 密码
    *
    * */
    @Column
    @NotNull
    private String password;

    /*
    * 姓名
    *
    * */
    @Column
    private String name;

    /**
     * E-mail
     */

    @Column
    private String email;

    /**
     * 手机
     *
     */
    @Column(unique=true)
    @NotNull
    private String mobile;


    /**
     * 积分
     */
    private Long point;

    /**
     * 余额
     */
    @Column(precision = 27, scale = 12)
    private BigDecimal balance;

    /**
     * 冻结金额
     */
    @Column(precision = 27, scale = 12)
    private BigDecimal frozenAmount;

    /**
     * 消费金额
     */
    @Column(precision = 27, scale = 12)
    private BigDecimal amount;

    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Gender {
        MAN("男"),
        WOMAN("女");
        Gender(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    /**
     * 性别
     */
    @Enumerated(EnumType.STRING)
    @Column
    private Gender gender;

    /**
     * 出生日期
     */
    @Column
    private Date birth;

    /**
     * 地址
     */
    @Length(max = 200)
    private String address;

    /**
     * 邮编
     */
    @Length(max = 200)
    private String zipCode;

    /**
     * 电话
     */
    @Length(max = 200)
    private String phone;


    /*
     * 用户状态
     *
     * */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Status {
        NO("禁用"),
        YES("启用");
        Status(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Type {
        ADMIN("管理员"),
        USER("商家"),
        BUSINESS("业务员");
        Type(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @Enumerated(EnumType.STRING)
    @Column
    private Type type;

    @Enumerated(EnumType.STRING)
    @Column
    private Status status;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @CreatedDate
    @Column
    private Date createTime;

    @Column
    private String icon;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @LastModifiedDate
    @Column
    private Date modifiedTime;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }



    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public Long getPoint() {
        return point;
    }

    public void setPoint(Long point) {
        this.point = point;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }

    public BigDecimal getFrozenAmount() {
        return frozenAmount;
    }

    public void setFrozenAmount(BigDecimal frozenAmount) {
        this.frozenAmount = frozenAmount;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getZipCode() {
        return zipCode;
    }

    public void setZipCode(String zipCode) {
        this.zipCode = zipCode;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }
}
